<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Payment
 *
 * @author Sorasak Siangsanan
 */
class Payment extends CActiveRecord {

    public $payment_id;
    public $full_name;

    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    public function primaryKey() {
        return 'payment_id';
    }

    public function tableName() {
        return "payment";
    }

    public function attributeLabels() {
        return array(
            "payment_id" => Yii::t('payment_model', 'payment_id'),
            "order_id" => Yii::t('payment_model', 'order_id'),
            "bank" => Yii::t('payment_model', 'bank'),
            "bank_branch" => Yii::t('payment_model', 'bank_branch'),
            "payment_date" => Yii::t('payment_model', 'payment_date'),
            "time" => Yii::t('payment_model', 'time_payment'),
            "full_name" => Yii::t('payment_model', 'full_name'),
            "mobilephone" => Yii::t('payment_model', 'mobilephone'),
            "amount" => Yii::t('payment_model', 'amount'),
            "remark" => Yii::t('payment_model', 'remark'),
            "create_date" => Yii::t('payment_model', 'create_date'),
        );
    }

    public function relations() {
        return array(
            'order' => array(self::BELONGS_TO, 'Order', 'order_id')
        );
    }

    public function rules() {
        return array(
            array('payment_id, full_name', 'safe', 'on' => 'search')
        );
    }

    public function search() {
        $criteria = new CDbCriteria;
        
        $criteria->with = array('order');
        
        $criteria->compare('t.payment_id', $this->payment_id, false);
        $criteria->compare('t.full_name', $this->full_name, true);

        return new CActiveDataProvider(get_class($this), array(
            'criteria' => $criteria,
            'pagination' => array(
                'pageSize' => 10
            ),
            'sort' => array(
                'defaultOrder' => 'order.status_id asc, t.create_date desc',
                'multiSort' => true,
            ),
                )
        );
    }

}
